<?php
namespace Admin\Controller;
use Think\Controller;

//---------------
//Author:Hua
//--------------

class CommentController extends CommonController {
    /*后台评论首页*/
    public function index(){
    	$com = D('Comments');
    	$list = $com->getAll();
    	$total = $com->count();
    	$this->assign('list',$list);
    	$this->assign('total',$total);
    	$this->display();
    }

    /*删除评论*/
    public function del(){
    	$id = $_GET['id'];

    	$com = D('Comments');
    	$com->delete($id);

    	$this->redirect('index');
    }

    /*评论回复*/
    public function reply(){

        if(IS_POST){
            $reply = D('Comments');
            $info = $reply->save($_POST);
            if($info){
                $data['id'] = $_POST['id'];
                $data['status'] = '1';
                $reply->save($data);
                $this->redirect('index');
            }else{

            }
            
        }else{
            $id = $_GET['id'];
            $this->assign('id',$id);
            $this->display();
        }

    }

    /*查看回复内容*/
    public function replyed(){
        $data['id'] = $_GET['id'];
        $reply = D('Comments');
        $info = $reply->where($data)->find();
        $this->assign('info',$info);
        $this->display();
    }
    
    /*查看订单小窗*/
    public function order(){
        $data['id'] = $_GET['id'];
        $order = D('Orders');
        $info = $order->where($data)->find();
        $info['addtime'] = date('Y-m-d H:i:s',$info['addtime']);
        $this->assign('info',$info);
        $this->display();
    }

    /*查看商品小窗*/
    public function goods(){
        $data['id'] = $_GET['id'];
        $goods = D('Goods');
        $info = $goods->where($data)->find();
        $info['addtime'] = date('Y-m-d H:i:s',$info['addtime']);
        $state = array('新添加','在售','下架');
        $info['state'] = $state[$info['state']];
        $this->assign('info',$info);
        $this->display();
    }

    /*查看用户信息小窗*/
    public function user(){
        $data['id'] = $_GET['id'];
        $user = D('User');
        $info = $user->where($data)->find();
        $sex = array('女','男');
        $info['sex'] = $sex[$info['sex']];
        $info['addtime'] = date('Y-m-d H:i:s',$info['addtime']);
        $this->assign('info',$info);
        $this->display();

    }

}
